﻿package net.chrisjrock.display
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	/**
	 * ...
	 * @author Christopher J. Rock
	 */
	public class FloatPrompt extends Sprite
	{
		protected var _container:Sprite;
		
		public function FloatPrompt ():void { ; }
		
		public function draw ():void {
			if (_container) removeChild(_container);
			
			_container = new Sprite();
			addChild(_container);
		}
		
		public function float ():void {
			addEventListener(Event.ENTER_FRAME , floatFrameHandler , false , 0 , true);
		}
		
		protected function floatFrameHandler (event:Event):void {
			_container.y -= 6 / 30;
			_container.alpha -= .25 / 30;
			
			if (_container.alpha <= .25 / 30) {
				removeEventListener(Event.ENTER_FRAME , floatFrameHandler);
				removeChild(_container);
				_container = null;
				if (parent) parent.removeChild(this);
			}
		}
		
		protected function get container ():Sprite { return _container; }
	}
	
}